package test.format_test;



import org.junit.Test;

import java.io.*;

public class ForIO {
    File file = new File("./generate");
    public static void main(String[] args) throws Exception {
        //File file = new File("./1");
        //file.mkdir();
        //file.createNewFile();
        FileInputStream fi = new FileInputStream("./1.text");
        int readData = 0;
        while ((readData = fi.read())!=-1){
            System.out.print((char)readData);
        }
        fi.close();
    }


    @Test
    public void outputStream() throws Exception {
        FileOutputStream fo = new FileOutputStream("./2.text");
        fo.write('n');
        //字节输出流不加close也可输出   字符要加是因为close方法底层调用的字节输出

    }

    @Test
    public void objectSe() throws Exception {
        file.mkdir();

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("./generate/light.dat"));
        light l = new light(300000);
        oos.writeObject(l);
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("./generate/light.dat"));
        Object o = ois.readObject();
        System.out.println(o);
        System.out.println(o.getClass());
        light rl = (light)o;
        System.out.println(rl.speed);
    }

    @Test
    public void outstream() throws Exception {
        FileOutputStream os = new FileOutputStream("./generate/ops.txt");
        os.write('蔡');
        os.close();
    }

}


class light implements Serializable{
    int speed;

    public light(int speed) {
        this.speed = speed;
    }

    @Override
    public String toString() {
        return "light{" +
                "speed=" + speed +
                '}';
    }
}

class ForIOBlock {
    File file = new File("./generate");

    public static void main(String[] args) throws Exception {
        //File file = new File("./1");
        //file.mkdir();
        //file.createNewFile();
        FileInputStream fi = new FileInputStream("./1.text");
        byte[] buf = new byte[3];
        fi.read(buf);
        System.out.println(new String(buf));
        System.out.println("可");
        fi.close();
    }
}